package com.googlecode.beanfiles.csv;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.googlecode.beanfiles.readers.ReaderIteratorBase;
import com.googlecode.beanfiles.translators.PropertyTranslator;

/**
 * Parses the input stream using CVSReader static methods.
 * 
 * <p>
 * Example usage (requires the first row to contain the MyBean property names as
 * column values):
 * 
 * <pre>
 * ReaderIterator&lt;MyBean&gt; iterator = new CSVReaderIterator&lt;MyBean&gt;(MyBean.class, inputStream);
 * for (MyBean bean : iterator) {
 * 	// do something with bean
 * }
 * </pre>
 * 
 * @param <T>
 *            Target type
 */
public class CSVReaderIterator<T> extends ReaderIteratorBase<T> {

	public CSVReaderIterator(Class<T> target, InputStream input, Map<String, PropertyTranslator> translators) {
		super(target, CSVReaderUtil.parseStandardCSV(new InputStreamReader(input)), translators);
	}

	public CSVReaderIterator(Class<T> target, InputStream input) {
		super(target, CSVReaderUtil.parseStandardCSV(new InputStreamReader(input)));
	}

	public CSVReaderIterator(Map<String, String> headingMap, Class<T> target, InputStream input) {
		super(target, headingMap, CSVReaderUtil.parseStandardCSV(new InputStreamReader(input)));
	}

	public CSVReaderIterator(Map<String, String> headingMap, Class<T> target, InputStream input, Map<String, PropertyTranslator> translators) {
		super(target, translators, headingMap, CSVReaderUtil.parseStandardCSV(new InputStreamReader(input)));
	}

	protected static Log log() {
		return LogFactory.getLog(CSVReaderIterator.class);
	}
}
